import { Component, OnInit } from '@angular/core';
import { HttpClient, HttpErrorResponse } from '@angular/common/http';
import { Carousel } from '../../model/carousel';
import { ActivatedRoute, Router } from '@angular/router';
import { CarouselService } from '../../service/carousel.service';

@Component({
  selector: 'app-upload',
  templateUrl: './upload.component.html',
  styleUrls: ['./upload.component.css']
})
export class UploadComponent implements OnInit {
  
  cl:Array<Carousel>;
  constructor(
  private http:HttpClient,
  private routerinfo:ActivatedRoute,
 private router:Router,
 private carouselservice:CarouselService) {

  }

  ngOnInit() {
    this.loadCarouselList();
  }
private loadCarouselList(){
  this.cl=new Array();

  this.carouselservice.getCarouselList()
  .then((data:any)=>{
    this.cl=data;
  })
}


  addCarousel(){
    this.router.navigate(['editCarousel','add']);
      }

  updateCarousel(id:string){
        this.router.navigate(['editCarousel',id]);
      }

  deleteCarousel(id:string){
     this.carouselservice.deleteCarousel(id)
     .then((flag:boolean)=>{
       if(flag==true){
         this.loadCarouselList();
       }else{
         alert("操作异常，请刷新后重试");
       }
     })
   }

}
